<template>
  <div style="width: 310px;margin: auto;margin-top: 300px">
    新密码：
    <el-input v-model="xuser" placeholder="请输入新密码" style="margin-top: 20px;width: 200px"></el-input><br>
    确认新密码：
    <el-input v-model="xxuser" placeholder="请再次输入新密码" style="margin-top: 20px;width: 200px"></el-input>
    <el-button type="primary" @click="update" style="size: 20px;margin-left: 20px">确认</el-button>
  </div>

  <el-dialog
      v-model="updateDiv"
      title=""
      width="20%"
      center>
    <h3>{{ this.updates }}</h3>
    <el-button type="primary" @click="this.updateDiv=false" style="margin-top: 30px;margin-left: 100px;size: 20px">确定
    </el-button>
  </el-dialog>
</template>

<script>
import axios from "axios";

export default {
  data() {
    return {
      xuser: "",
      xxuser: "",
      loginUser: {},
      updateDiv: false,
      updates: "",
    }
  },
  methods: {
    getLoginUser() {
      axios.get("/project/user/getLoginUser").then(resp => {
        this.loginUser = resp.data;
      })
    },
    update() {
      if (this.xuser != this.xxuser) {
        this.updateDiv = true;
        this.updates = "二次新密码不一样";
      } else {
        axios.get("/project/user/updatePwd", {
          params: {
            userId: this.loginUser.id,
            pwd: this.xuser
          }
        }).then(resp => {
          if (resp.data == "ok") {
            this.updateDiv = true;
            this.updates = "修改成功";
          }
        })
      }
    }
  },
  created() {
    this.getLoginUser();
  }
}
</script>

<style scoped>

</style>